"""技能系统"""


#%% 右边
class SkillImpactEffect:
    """父类,技能影响效果，约束子类"""
    
    def impact(self):
        raise NotImplementedError
    
    
class DamageEffect(SkillImpactEffect):
    """伤害生命效果"""
    def __init__(self, value):
        self.value = value
    
    
    def impact(self):
        print(f"扣你{self.value}血。")
        
        
class LowerDeffenseEffect(SkillImpactEffect):
    """降低防御力"""
    def __init__(self, value, time):
        self.value = value
        self.time = time
    
    
    def impact(self):
        print(f"降低{self.value}防御力，持续{self.time}秒！")
    
    
class DizzinessEffect(SkillImpactEffect):
    """眩晕"""
    def __init__(self, time):
        self.time = time
    
    
    def impact(self):
        print(f"眩晕持续了{self.time}秒！")    
    


#%% 左边，要用的人
class SkillDeployer:
    """技能释放器"""
    
    
    def load_config_file(self):
        # 假如加载进来了
        return {
            "降龙十八掌" : ["DamageEffect(200)", "LowerDeffenseEffect(-10, 5)", "DizzinessEffect(5)"],
            "六脉神剑" : ["DamageEffect(100)", "DizzinessEffect(6)"],
        }
    
    
    # 创建效果对象
    def create_effect_objects(self):
        # 根据name创建相应的技能对象
        list_effect_name = self.__dict_skill_config[self.name]
        list_effect_object = []
        for item in list_effect_name:
            list_effect_object.append(eval(item))
        return list_effect_object
    
    # 生成技能（执行效果）
    def generate_skill(self):
        print(f"{self.name}释放啦！")
        for item in self.__effect_objects:
            item.impact()
    
    
    def __init__(self, name) -> None:
        self.name = name
        # 加载配置文件，不然不知道调用那个
        self.__dict_skill_config = self.load_config_file();
        # 创建效果对象
        self.__effect_objects = self.create_effect_objects()
    
    
    
xlsbz = SkillDeployer("降龙十八掌")
xlsbz.generate_skill()
    
    
    
    